package com.u.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.http.protocol.RequestDate;

/**
 * Servlet implementation class SeachListServlet
 */
@WebServlet("/SeachListServlet")
public class SeachListServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SeachListServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		HttpSession session = request.getSession();
		String station_id = request.getParameter("bank_id");
		String month = request.getParameter("month");
		String day = request.getParameter("day");
		System.out.println(station_id + " " + month + " " + day);
		StringBuilder datebuild = new StringBuilder("2018-");
		String date = null;
		if(month.equals("0")) {
			date = datebuild.toString();
		}else if(day.equals("0")) {
			datebuild.append(month + "-");
		}else {
			datebuild.append(month + "-" + day);
		}
		session.setAttribute("station_id", station_id);
		session.setAttribute("date", date);
		request.setAttribute("page", "1");
		request.setAttribute("selected", true);
		System.out.println(request.getParameter("page"));
		RequestDispatcher requestDispatcher = request.getRequestDispatcher("/GetEventListService");
		requestDispatcher.forward(request, response);
		
	}

}
